<template>
	<div class="flex-col">
		<div style="margin-bottom: 50px;">
			<customer-Info  v-model="detailForm" v-if="detailForm.customerDetailVo" />
			<customer-Order-Info  v-model="detailForm" v-if="detailForm.orderInfoVo" />
			<div v-if="detailForm.carBasicVo">
				<external-Leasing-Info v-model="detailForm" v-if="isShow" />
				<procurement-Info v-model="detailForm" v-else />
			</div>
			<car-Info v-model="detailForm" v-if="detailForm.carBasicVo" />
			<div v-if="detailForm.carInStorage">
				<improve-Info v-model="detailForm" ref='refImprove' v-if="!boole && detailForm.carInStorage"/>
				<template v-else>
				  <view class="normal-login-container">
				
				    <view class="item-wrap" style="margin-bottom: 0">
				      <view class="lineBottom10">
				        <uni-section title="入库信息" type="line"/>
				      </view>
				
				      <view style="margin: 8rpx 20rpx 8rpx 20rpx">
				        <uni-forms ref="form" :rules="rules" label-position="top" :model="form"
				                   labelWidth="auto">
							<uni-forms-item label="车牌号:" name='carNo' required="true">
								 <uni-easyinput  v-model="form.carNo" placeholder="请输入车牌号"/>
							</uni-forms-item>
							<uni-forms-item label="年检线上线下:" name='inStorageOnlineOffline' required="true">
							  <uni-data-select
							       v-model="form.inStorageOnlineOffline"
							       :localdata="yearOptions"
							     ></uni-data-select>
							</uni-forms-item>
							<uni-forms-item label="是否我司年检:" name='isOurCompanyInspection' required="true">
							  <uni-data-select
							       v-model="form.isOurCompanyInspection"
							       :localdata="companyOptions"
							     ></uni-data-select>
							</uni-forms-item>
							<uni-forms-item label="年检到期日:" name='inStorageInspectionExpire' required="true">
							  <uni-datetime-picker  type="date" placeholder="请选择年检到期日" return-type="string"
							    v-model="form.inStorageInspectionExpire" />
							</uni-forms-item>
							<uni-forms-item label="入库里程(km):" name='inboundMileage' required="true">
							  <uni-easyinput  v-model="form.inboundMileage" placeholder="请输入入库里程"/>
						
							</uni-forms-item>
							<uni-forms-item label="入库里程附件:" name='inboundMileageOss' required="true">
									<image-common :disabled="!boole" :up-type="2" v-model="form.inboundMileageOss"/>
							</uni-forms-item>
							  <uni-forms-item label="入库油量(%):" name='inboundOilQuantity' required="true">
								<uni-easyinput  v-model="form.inboundOilQuantity" placeholder="请输入入库油量"/>
								
							  </uni-forms-item>
							  <uni-forms-item label="入库油量附件:" name='inboundOilQuantityOss' required="true">
								<image-common :disabled="!boole" :up-type="2" v-model="form.inboundOilQuantityOss"/>
							  </uni-forms-item>
				
							  <uni-forms-item label="上传行使证:" name='drivingLicenseOss' required="true">
								<image-common :disabled="!boole" :up-type="2" v-model="form.drivingLicenseOss"/>
							  </uni-forms-item>
				
							  <uni-forms-item label="上传车辆照片:" name='carPhotoOss' required="true">
								<image-common :disabled="!boole" :up-type="2" v-model="form.carPhotoOss"/>
							  </uni-forms-item>
				
							  <uni-forms-item label="上传登记照片:" name='registrationCertificateOss' required="true">
								<image-common :disabled="!boole" :up-type="2" v-model="form.registrationCertificateOss"/>
							  </uni-forms-item>
							  <uni-forms-item label="上传入库年检附件:" name='inspectionOss' >
								<image-common :disabled="!boole" :up-type="2" v-model="form.inspectionOss"/>
							  </uni-forms-item>
							  <uni-forms-item label="附件:" name='attachmentOss'>
							  				<image-common :disabled="!boole" :up-type="2" v-model="form.attachmentOss"/>
							  </uni-forms-item>
							  
							  <uni-forms-item label="备注:" name='remark'>
									<uni-easyinput  v-model="form.remark" placeholder="请输入备注"/>	
							  </uni-forms-item>
				        </uni-forms>
				      </view>
				    </view>
				  </view>
				</template>
			</div>
			
			<!--审批流程-->
			<exam-flow v-if="flowId" :instanceId="flowId"/>
		</div>
		<view class="button-container" v-if="boole">
			<button class="btn-item" @click="submit(1)">保 存</button>
		  <button class="btn-item" @click="submit(2)">提 交</button>
		</view>
	</div>
</template>

<script>
	import customerInfo from '../compoents/customer.vue'
	import customerOrderInfo from '../compoents/orderInfo.vue'
	import procurementInfo from '../compoents/procurement.vue'
	import carInfo from '../compoents/car.vue'
	import improveInfo from '../compoents/improve.vue'
	import externalLeasingInfo from '../compoents/externalLeasing.vue'
	import {getInstorageInfo,postInstorage,insertCarInStorage} from "@/api/storage/in.js";
export default {
  name: 'instorageInfo',//详情
  components: {customerInfo,customerOrderInfo,procurementInfo,carInfo,improveInfo,externalLeasingInfo},
  watch: {
	 form:{
		 deep:true,
		 handler(val){
			 this.form = val
		 }
	 }
  },
  data() {
    return {
		detailForm:{},
		flowId:'',
		id:'',
		isShow:false,
		boole:true,
		form:{
			carNo:'',
			inboundMileage:'',
			inboundMileageOss:'',
			inboundOilQuantity:'',
			inboundOilQuantityOss:'',
			drivingLicenseOss:'',
			carPhotoOss:'',
			registrationCertificateOss:'',
			attachmentOss:'',
			inspectionOss:'',
			isOurCompanyInspection:'',
			inStorageOnlineOffline:'',
			inStorageInspectionExpire:'',
		},
		rules: {
			  inboundMileage: {
			    rules: [
			      {
			        required: true,
			        errorMessage: "请输入入库里程",
			        validateTrigger: "blur",
			      },
			    ],
			  },
			  inStorageOnlineOffline: {
			    rules: [
			      {
			        required: true,
			        errorMessage: "请选择年检线上线下",
			        validateTrigger: "change",
			      },
			    ],
			  },
			  isOurCompanyInspection: {
			    rules: [
			      {
			        required: true,
			        errorMessage: "请选择是否我司年检",
			        validateTrigger: "change",
			      },
			    ],
			  },
			  inStorageInspectionExpire: {
			    rules: [
			      {
			        required: true,
			        errorMessage: "请选择年检到期日",
			        validateTrigger: "change",
			      },
			    ],
			  },
			  inboundMileageOss: {
			    rules: [
			      {
			        required: true,
			        errorMessage: "请输入入库里程表",
			        validateTrigger: "blur",
			      },
			    ],
			  },
			  inboundOilQuantity: {
			    rules: [
			      {
			        required: true,
			        errorMessage: "请输入入库油量",
			        validateTrigger: "bind",
			      },
			    ],
			  },
			  inboundOilQuantityOss: {
			    rules: [
			      {
			        required: true,
			        errorMessage: "请输入入库油量表",
			        validateTrigger: "bind",
			      },
			    ],
			  },
			  drivingLicenseOss: {
			    rules: [
			      {
			        required: true,
			        errorMessage: "行使证",
			        validateTrigger: "bind",
			      },
			    ],
			  },
			  carPhotoOss: {
			    rules: [
			      {
			        required: true,
			        errorMessage: "车辆照片",
			        validateTrigger: "bind",
			      },
			    ],
			  },
			  registrationCertificateOss: {
			    rules: [
			      {
			        required: true,
			        errorMessage: "登记照片",
			        validateTrigger: "bind",
			      },
			    ],
			  },
			  attachmentOs: {
			    rules: [
			      {
			        required: true,
			        errorMessage: "附件",
			        validateTrigger: "bind",
			      },
			    ],
			  },
		},
		yearOptions:[
			{ value: '1',text: '线上'},
			{ value: '2',text: '线下'},
		],
		companyOptions:[
			{ value: '0',text: '是'},
			{ value: '1',text: '否'},
		],
	};
  },
  onLoad(op) {
    this.flowId = op?.flowId;
	this.id = op?.id
	if(op?.viewType==0){
		this.boole = false
	}else{
		this.boole = true
	}
	console.log(typeof op?.source)
	 // 1是外部转租赁 展示外部转租赁模块 2是正常展示采信息
		if(op?.source == '1'){
			this.isShow = true
		}else{
			this.isShow = false
		}
	this.getInfo()
  },
  mounted() {
  },
  methods: {
	  getInfo(){
		  getInstorageInfo(this.id).then((res)=>{
			  if(res.code==200){
				   this.flowId = res.data?.carInStorage?.flowId
				  for (const key in res.data) {
				    this.$set(this.detailForm, key, res.data[key]);
				  }
				  this.$set(this.detailForm,'inboundId',this.id)
				  this.$set(this.detailForm,'source',this.source)
				  for (const key in res.data?.carInStorage) {
				    this.$set(this.form, key, res.data.carInStorage[key]);
				  }
			  }
		  })
	  },
	  submit(type){
		  if(type==1){
			  for (const key in this.form) {
			    this.$set(this.detailForm.carInStorage, key, this.form[key]);
			  }
			  insertCarInStorage(this.detailForm).then((res)=>{
				  if (res.code === 200) {
					uni.$emit("refreshClue", true);
					this.$modal.msgSuccess("提交成功");
					setTimeout(() => {
						// let url = `/pages/StoragePage/inStorage/list`
						this.$tab.navigateBack()
					}, 1000);
				  }
			  })
		  }else{
			  this.$refs.form
			      .validate()
			      .then((res) => {
					  for (const key in this.form) {
						this.$set(this.detailForm.carInStorage, key, this.form[key]);
					  }
					  postInstorage(this.detailForm).then((res)=>{
						  if (res.code === 200) {
						  uni.$emit("refreshClue", true);
							this.$modal.msgSuccess("提交成功");
							setTimeout(() => {
							  // let url = `/pages/StoragePage/inStorage/list`
							  this.$tab.navigateBack()
							}, 1000);
						  }
					  })
			      })
		  }
		 
	  },
  },
};
</script>

<style>
</style>